package com.heima.crm.controller;

import com.heima.crm.common.result.Result;
import com.heima.crm.pojos.dtos.PostPageDTO;
import com.heima.crm.pojos.entity.SysPost;
import com.heima.crm.service.PostService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/system/post")
@Slf4j
public class SysPostController {

    @Autowired
    private PostService postService;

    /**
     * 岗位动态模糊分页条件查询
     *
     * @param postPageDTO
     * @return
     */
    @GetMapping("/list")
    public Result postPageList(PostPageDTO postPageDTO) {
        log.info("岗位动态模糊分页条件查询:{}", postPageDTO);
        return postService.postPageList(postPageDTO);///======
    }

    /**
     * 添加岗位
     *
     * @param sysPost
     * @return
     */
    @PostMapping("/add")
    public Result addPost(@RequestBody SysPost sysPost) {
        log.info("添加岗位:{}", sysPost);
        return postService.addPost(sysPost);
    }

    /**
     * 修改岗位
     *
     * @param sysPost
     * @return
     */
    @PutMapping("/update")
    public Result updatePost(@RequestBody SysPost sysPost) {
        log.info("修改岗位:{}", sysPost);
        return postService.updatePost(sysPost);
    }

    //回显
    @GetMapping("/{id}")
    public Result<SysPost> selectById(@PathVariable Long id) {

        SysPost sysPost = postService.getById(id);

        return Result.success(sysPost);
    }

    /**
     * 删除岗位
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result deletePost(@PathVariable Long id) {
        log.info("删除岗位:{}", id);
        return postService.deletePost(id);
    }

    @PostMapping("/{status}/{id}")
    public Result startOrStop(@PathVariable Integer status, @PathVariable Long id) {
        log.info("岗位启停:{},{}", status, id);
        return postService.startOrStop(status, id);
    }
}
